package ua.maxicash.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Service;
import ua.maxicash.vo.Work;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

//@Service("AlertService")
public class AlertServiceImpl implements AlertService{

    @Autowired
    JmsTemplate jmsTemplate;

    @Override
    public void sendNewWorkAlert(final Work work) {
        jmsTemplate.send("new.work.alert.queue",new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
                return session.createObjectMessage(work);
            }
        });
    }

    @Override
    public void sendEditedWorkAlert(final Work work) {
        jmsTemplate.send("edit.work.alert.queue",new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
                return session.createObjectMessage(work);
            }
        });
    }
}
